﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

using Shove.Web.UI;

public partial class UserControls_News2 : UCBase
{
    public UserControls_News2()
    {
        Name = "最新消息";

        swpas = new ShoveWebPartAttribute[15];

        swpas[0] = new ShoveWebPartAttribute_Int("最新消息图片行高", "1,200", 22, "最新消息图片行高");
        swpas[1] = new ShoveWebPartAttribute_Int("控件宽度", "1,1000", 200, "控件宽度");
        swpas[2] = new ShoveWebPartAttribute_Int("控件高度", "1,1000", 212, "控件高度");
        swpas[3] = new ShoveWebPartAttribute_Int("最新消息图片宽度", "1,1000", 200, "最新消息图片宽度");
        swpas[4] = new ShoveWebPartAttribute_Int("最新消息图片高度", "1,1000", 21, "最新消息图片高度");
        swpas[5] = new ShoveWebPartAttribute_Int("标题行高", "1,300", 20, "标题行高");
        swpas[6] = new ShoveWebPartAttribute_Int("标题左边距", "1,300", 10, "标题左边距");

        swpas[7] = new ShoveWebPartAttribute_Image("最新消息图片","","images/zxxx.gif","最新消息图片");
        swpas[8] = new ShoveWebPartAttribute_Color("控件边框颜色", "#eaeaea", "控件边框颜色");
        swpas[9] = new ShoveWebPartAttribute_Color("最新消息行背景颜色", "#f8c4d6", "最新消息行背景颜色");

        swpas[10] = new ShoveWebPartAttribute_Text("消息标题CSS样式", "", "black12", "消息标题CSS样式");
        swpas[11] = new ShoveWebPartAttribute_Text("标题列表CSS样式", "", "black12", "标题列表CSS样式");
        swpas[12] = new ShoveWebPartAttribute_Text("标题列表行CSS样式", "", "news_list", "标题列表行CSS样式");
  
        swpas[13] = new ShoveWebPartAttribute_Int("行数", "1,100", 8, "显示公告的条数");
        swpas[14] = new ShoveWebPartAttribute_Int("每行截取字数", "1,200", 16, "公告标题显示字数");
    }

    private void Initlayout()
    {
        tabctr.Width = swpAttributes[1];
        tabctr.Height = swpAttributes[2];
        tabctr.BorderColor = swpAttributes[8];
        tdimg.Height = swpAttributes[0];
        span1.Style.Add("background-color",swpAttributes[9]);
        tdnews.Src = "~/" + swpAttributes[7];
        tdnews.Width = Shove._Convert.StrToInt(swpAttributes[3], 91);
        tdnews.Height = Shove._Convert.StrToInt(swpAttributes[4], 21);
        tdText.Attributes.Add("class", swpAttributes[12]);
        dlNew.CssClass = swpAttributes[11];
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Initlayout();
            BindData();
        }
    }

    protected void dlNew_ItemDataBound(object sender, DataListItemEventArgs e)
    {
        HyperLink hlNews = (HyperLink)e.Item.FindControl("hlNews");
        TextBox tbID = (TextBox)e.Item.FindControl("tbID");

        hlNews.Text = Shove._String.Cut(hlNews.Text, Shove._Convert.StrToInt(swpAttributes[14], 16));
        hlNews.NavigateUrl = "~/Default.aspx?PN=article_details&ID=" + tbID.Text;

        HtmlTableCell tdtitle = (HtmlTableCell)e.Item.FindControl("tdtitle");
        tdtitle.Attributes.Add("class", swpAttributes[10]);
        tdtitle.Height = swpAttributes[5];
        tdtitle.Style.Add("padding-left", swpAttributes[6] + "px");
    }

    private void BindData()
    {
        DataTable dt = new DataTable();
        long ShopID = _Site.ID;

        dt = new DAL.Views.V_Site_Article().Open(" top " + Shove._Convert.StrToInt(swpAttributes[13], 10) + " *", "isShow=1 and ArticleTypeName = '商店公告' and ShopID =" + ShopID, "");

        if (dt.Rows.Count > 0)
        {
            dlNew.DataSource = dt;
            dlNew.DataBind();
        }

    }
}
